/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Logika;

/**
 *
 * @author mejcu
 */
public class Register {
    public static final int SIZE=4;
    private String [] registerString =new String[SIZE];
    private int    [] registerInt    ={-1,-1,-1,-1};
    private int       currentPointer=0;
    private boolean   deleted       =false;
    private int current;


    public Register()
    {}

    public int add(String clientAdress)
    {
        if(deleted)
        {
            return addToDifferentPlace(clientAdress);
        }
        else
        {
            registerString[currentPointer]=clientAdress;
            registerInt[currentPointer]=1;
            System.out.println("Dodano na pozycje "+currentPointer);
            currentPointer++;
        }
        return currentPointer;//Zmienilem
    }

    public void remove(String clientAdress)
    {
        for(int i=0; i<currentPointer; i++)
        {
            if(registerString[i].compareTo(clientAdress)==0)
            {
                registerString[i]=null;
                registerInt[i]=-1;
                deleted=true;
                System.out.println("-----------------------------------------");
                System.out.println("Usunieto "+clientAdress);
                if(i==(currentPointer-1))
                {
                    currentPointer--;
                }
                break;
            }
        }
    }


    private int addToDifferentPlace(String clientAdress)
    {
        int i=0;
        for(i=0; i<currentPointer; i++)
        {
            if(registerInt[i]<0)
            {
                break;
            }
        }
        System.out.println("Dodano w inne miejsce "+i);
        registerString[i]=clientAdress;
        registerInt[i]=1;
        deleted=false;
        if(i==currentPointer)
        {
            currentPointer++;
        }
        return i+1;
    }

}
